package uit.com.project.iCampus.activity;

import java.util.List;

import uit.com.project.iCampus.map.CustomItemizedOverlay;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class GMapsActivity extends MapActivity {
	
	private MapView mapView;
	
	private static final double latitudeE6 = 10.870485;
	private static final double longitudeE6 = 106.802065;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mapView = (MapView) findViewById(R.id.map_view);       
        mapView.setBuiltInZoomControls(true);
        
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.my_location);
		CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
		
		GeoPoint point = new GeoPoint((int) (latitudeE6 * 1E6), (int) (longitudeE6 * 1E6));
		OverlayItem overlayitem = new OverlayItem(point, "Hello", "I'm in UIT, Viet Nam!");
		
		itemizedOverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedOverlay);
		
		MapController mapController = mapView.getController();
		
		mapController.animateTo(point);
		mapController.setZoom(6);
        
    }

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
      MenuInflater menuInflater = getMenuInflater();
      menuInflater.inflate(R.layout.main_menu, menu);
      return true;
  }
  
  /**
   * Event Handling for Individual menu item selected
   * Identify single menu item by it's id
   * */
  @Override
  public boolean onOptionsItemSelected(MenuItem item)
  {

      switch (item.getItemId())
      {
      case R.id.menu_direction:
          // Single menu item is selected do something
          // Ex: launching new activity/screen or show alert message
          Toast.makeText(this, "Circle Finding is Selected", Toast.LENGTH_SHORT).show();
          return true;

      case R.id.menu_statistic:
          Toast.makeText(this, "Statistic is Selected", Toast.LENGTH_SHORT).show();
          Intent s = new Intent(this, Statistic.class);
	  		startActivity(s);
	  		finish();
          return true;

      case R.id.menu_search:
          Toast.makeText(this, "Search is Selected", Toast.LENGTH_SHORT).show();
          return true;

      case R.id.menu_back:
          Toast.makeText(this, "Back is Selected", Toast.LENGTH_SHORT).show();
          Intent b = new Intent(this, GMapsActivity.class);
    		startActivity(b);
    		finish();
        
          return true;

      case R.id.menu_onlineusers:
          Toast.makeText(this, "Online Users are Selected", Toast.LENGTH_SHORT).show();
          return true;

      case R.id.menu_option:
          Toast.makeText(this, "Option is Selected", Toast.LENGTH_SHORT).show();
          Intent a = new Intent(this, Options_menu.class);
      		startActivity(a);
      		finish();
          return true;

      default:
          return super.onOptionsItemSelected(item);
      }
  }    
}